package role
{
	import flash.display.BitmapData;
	import flash.events.EventDispatcher;
	
	public class RoleCharacterCreateStateBase extends EventDispatcher
	{
		private var _stateXml:XML;
		private var _actions:XMLList;
		private var _stateType:String;
		private var _stateName:String;
		private var _roleCharacterStateItem:RoleCharacterStateItem;
		private var _roleCharacterSet:RoleCharacterSet=new RoleCharacterSet();
		private var _roleCharacterActionSet:RoleCharacterActionSet=new RoleCharacterActionSet();
		
		public function RoleCharacterCreateStateBase(stateXml:XML)
		{
			_stateXml=stateXml;
			
			createStateAction();
		}
		
		public function get stateXml():XML
		{
			return _stateXml;
		}
		
		private function createStateAction():void
		{
			_stateType=_stateXml.@type;
			_stateName=_stateXml.@name;
			
			_actions=_stateXml.actions.action;
			
			for each(var item:XML in _actions)
			{//动作集处理
				var roleCharacterCreateActionBase:RoleCharacterCreateActionBase=new RoleCharacterCreateActionBase();
				roleCharacterCreateActionBase.actionName=item.@name;
				roleCharacterCreateActionBase.actionType=item.@type;
				roleCharacterCreateActionBase.frames=item.frame.@value.toString().split(',');
				roleCharacterCreateActionBase.actionRepeat=item.@repeat=="true";
				roleCharacterCreateActionBase.assetList=item.assets.asset;
				roleCharacterCreateActionBase.addEventListener(RoleCharacterEvent.CHARACTER_ACTIONBASE_ALL_LOAD_COMPLETE, actionBaseComplete);
			}
		}
		
		private function actionBaseComplete(evt:RoleCharacterEvent):void
		{
			var ra:RoleCharacterCreateActionBase=evt.data as RoleCharacterCreateActionBase;
			
			_roleCharacterActionSet.push(new RoleCharacterActionItem(ra.actionType, ra.frames, ra.actionRepeat));
			
			for each(var rc:RoleCharacterItem in ra.roleCharacterItemList)
			{
				_roleCharacterSet.push(rc);
			}
			
			if(_roleCharacterActionSet.length>=_actions.length())
			{
				_roleCharacterStateItem=new RoleCharacterStateItem(_stateType, _roleCharacterSet, _roleCharacterActionSet);
				dispatchEvent(new RoleCharacterEvent(RoleCharacterEvent.CHARACTER_STATEBASE_ALL_LOAD_COMPLETE, _roleCharacterStateItem));
			}
		}
		
		public function get stateType():String
		{
			return _stateType;
		}
		
		public function set stateType(value:String):void
		{
			_stateType = value;
		}
		
		public function get stateName():String
		{
			return _stateName;
		}
		
		public function set stateName(value:String):void
		{
			_stateName = value;
		}
	}
}